package com.example.adminsystem.controller;

import com.example.adminsystem.common.ResponseResult;
import com.example.adminsystem.entity.Router;
import com.example.adminsystem.repository.RouterRepository;
import com.example.adminsystem.req.RouterReq;
import com.example.adminsystem.service.RouterService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/router")
public class RouterController extends BaseCrudController<Router, Long,RouterReq.AddRouterRequest, RouterReq.AddRouterRequest, RouterReq.RouterQuery > {

    @Autowired
    private RouterRepository routerRepository;

    @Autowired
    private RouterService routerService;

    @Override
    protected RouterRepository getRepository() {
        return routerRepository;
    }

    @Operation(summary = "注册用户", description = "注册用户")
    @GetMapping("/front")
    public ResponseResult<?> getFrontRouters() {
        // 从安全上下文中获取认证信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        // 获取用户名（通常是字符串）
        String username = authentication.getName();
        System.out.println(username);
        // 定义一个列表：[1,2,3]
        List<Long> routerIds = Arrays.asList(1L, 2L, 3L);
        return  ResponseResult.success(routerService.getFrontRouters(routerIds));
    }


}
